﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bootstrap.MVC.Utils;

namespace Bootstrap.MVC.Infrastructure.ClientEvent
{
    public class ClientEventManager
    {

        private readonly List< ClientEvent> eventBag;
        public List<ClientEvent> EventBag
        {
            get { return eventBag; }
        }

        public ClientEventManager()
        {
            eventBag = new List<ClientEvent>();
        }

        public ClientEventManager Register(ClientEvent clientEvent)
        {
            Guard.IsNotNull(clientEvent, "clientEvent");

            eventBag.RemoveAll( e => e.EventName == clientEvent.EventName);
            eventBag.Add(clientEvent);
            return this;
        }

        public ClientEventManager Register(string eventName, string handler)
        {
            Guard.IsNotNull(eventName, "eventName");

            eventBag.RemoveAll(e => e.EventName == eventName);
            eventBag.Add( new ClientEvent(eventName , handler));
            return this;
        }
    }
}
